﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;

namespace CellsLifeActivity
{
    class Cell:ICloneable
    {
        public object Clone()
        {
            Cell clone = new Cell();
            clone = this;
            return clone;
        }

        public virtual char DrawCell()
        {
            return '!';
        }

        /// <summary>
        /// Method, which implements cell death because of solitude. If condition is fulfilled the 
        /// method returns empty (i. e. died) cell, else it returns current object without changes 
        /// </summary>
        /// <param name="cCount">number of neighbours with the same kind</param>
        /// <param name="c">a certain cell. It will be taken from cells' matrix </param>
        /// <returns>new or old cell</returns>
        public virtual Cell DieAlone(int cCount,Cell c)
        {

            if (cCount < 3) //3 the condition parameter, which user can choose
                c= new EmptyCell();
            return c;

        }

        /// <summary>
        /// Method, which implements cell death because of overpopulation. If condition is fulfilled the 
        /// method returns empty (i. e. died) cell, else it returns current object without changes 
        /// </summary>
        /// <param name="cCount">number of not empty neighbours</param>
        /// <param name="c">a certain cell. It will be taken from cells' matrix </param>
        /// <returns>new or old cell</returns>
        public virtual Cell DieOverpopulation(int cCount, Cell c)
        {

            if (cCount < 2) //3 the condition parameter, which user can choose
                c = new EmptyCell();
            return c;

        }

        /// <summary>
        /// Method, which implements cell birth. Depanding on condition
        /// common or predatory cell can be borned
        /// </summary>
        /// <param name="cCount">number of common neighbours</param>
        /// <param name="pCount">number of predatory neighbours</param>
        /// <param name="c">a certain cell. It will be taken from cells' matrix</param>
        /// <returns>new cell</returns>
        public Cell MadeNewCell(int cCount,int pCount,Cell c)
        {
            if ((cCount > pCount) && (cCount >= Convert.ToInt32(GameLogic.SRet2))) //choose the type of new borning cell 
                c = new CommonCell();
            else
                if ((cCount <= pCount) && (pCount >= Convert.ToInt32(GameLogic.SRet3)))
                c = new PredatoryCell();
            return c;
        }

        /// <summary>
        /// Method, which implements eating of cell
        /// </summary>
        /// <param name="cCount">number of common neighbours (must be 1)</param>
        /// <param name="c">a certain cell (must be common cell). It will be taken from cells' matrix</param>
        /// <returns>new or old cell</returns>
        public Cell EatNeighbour(int cCount, Cell c)
        {
            if (cCount == 1)
                c = new EmptyCell();
            return c;
        }
    }

    class EmptyCell:Cell
    {
        public override char DrawCell()
        {
            return ' ';
        }
    }

    class CommonCell:Cell
    {
        public override char DrawCell()
        {
            return '*';
        }

        public override Cell DieAlone(int cCount, Cell c)
        {
            if (cCount < Convert.ToInt32(GameLogic.SRet5))  //4- NumberOfSameKindNeighbours the condition parameter, which user can choose
                c = new EmptyCell();
            return c;
        }

        public override Cell DieOverpopulation(int cCount, Cell c)
        {

            if (cCount < Convert.ToInt32(GameLogic.SRet4)) //1- NumberOfEmptyNeighbours the condition parameter, which user can choose
                c = new EmptyCell();
            return c; 

        }
    }

    class PredatoryCell:Cell
    {
        public override char DrawCell()
        {
            return 'X';
        }

        public override Cell DieAlone(int cCount, Cell c)
        {
            if (cCount < Convert.ToInt32(GameLogic.SRet7)) //3- NumberOfSameKindNeighbours the condition parameter, which user can choose
                c= new EmptyCell();
            return c;
        }

        public override Cell DieOverpopulation(int cCount, Cell c)
        {
            if (cCount < Convert.ToInt32(GameLogic.SRet6)) //6- NumberOfEmptyNeighbours the condition parameter, which user can choose
                c = new EmptyCell();
            return c;

        }
    }
}
